/*****************************************************************************************
 * Dexter : Distributed Experimental and Tester Platform
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *****************************************************************************************/
package dexter.net.msg;

import java.io.PrintWriter;
import java.io.StringWriter;

import dexter.net.msg.common.ResponseParams;

public class ResponseMessage extends AbstractMessage {
	
    private static final long serialVersionUID = 7371210248110219946L;

    private boolean ok;
    private ResponseParams result;
    private String error;

    public ResponseMessage() {
    	super(MessageType.RESPONSE_MESSAGE);
    }

    public boolean isOk() {
        return ok;
    }

    public void setOk(boolean ok) {
        this.ok = ok;
    }

    public ResponseParams getResult() {
        return result;
    }

    public void setResult(ResponseParams result) {
        this.result = result;
    }
    
	public void setError(Exception e) {
		StringWriter sw = new StringWriter(); 
	    PrintWriter pw = new PrintWriter(sw);
	    e.printStackTrace(pw); 
		this.error = sw.toString();		
	}
	
	public String getError() {
		return error;
	}

    public String toString() {
        if (ok) {
            return "ResponseMessage (" + result + ')';
        } else {
        	return "ResponseMessage ( ERROR : " + error + ')';
        }
    }



}